<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>ref</title>
    <script src='./vue.global.js'></script>
</head>
<body>
    <div id='app'>
        <!-- 给DOM元素/子组件一个引用它的名字ip -->
        <base-input ref="bi"></base-input>
    </div>

    <script>
        const app = Vue.createApp({
            data(){
                return {}
            },
            methods:{},
            computed:{},

            /* 父组件挂载完毕后勒令子组件聚焦 */
            mounted(){
                this.$refs.bi.focusTheFuckingInput()
            }
        })

        app.component("base-input",{

            // 给DOM元素一个引用它的名字ip
            template:`<input ref="ip">`,

            methods:{
                focusTheFuckingInput(){
                    this.$refs.ip.focus()
                }
            },

            /* 组件一旦挂载完毕就让input框聚焦 */
            // mounted(){
            //     // 通过ip逮到对应的DOM元素并令其聚焦
            //     this.$refs.ip.focus()
            // }

        })

        app.mount('#app')
    </script>
</body>
</html>